﻿Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Namespace Web.UI
    Public Class ToolKitUserControl
        Inherits System.Web.UI.UserControl

        ''' <summary>
        ''' Makes the ToolKitPage.Javascript available inside the user control.
        ''' </summary>
        ''' <returns>Javascript.ToolKitTools</returns>
        Public ReadOnly Property Javascript() As Javascript.ToolKitTools
            Get
                Return Nothing 'ToolKitPage.Javascript
            End Get
        End Property

        ''' <summary>
        ''' Makes the ToolKitPage available inside the user control without casing it.
        ''' </summary>
        ''' <returns>ToolKitPage</returns>
        Public ReadOnly Property ToolKitPage() As Web.UI.ToolKitPage
            Get
                Return DirectCast(Page, Web.UI.ToolKitPage)
            End Get
        End Property
        ''' <summary>
        ''' RegisterControl for use in Javscript from design view.
        ''' <example>OnPreRender="AddToJavascript"</example>
        ''' </summary>
        Protected Sub AddToJavascript(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim cntrl As Control = CType(sender, Control)
            Javascript.RegisterControl(cntrl)
        End Sub

        ''' <summary>
        ''' Makes sure a ToolKitPage is available.
        ''' </summary>
        Protected Overrides Sub OnLoad(ByVal e As EventArgs)
            If Not TypeOf Me.Page Is Web.UI.ToolKitPage Then
                Throw New Exception("Page must Inherit from Web.UI.ToolKitPage")
            End If
            MyBase.OnLoad(e)
        End Sub
    End Class
End Namespace